package cn.op.portal.common.vo;

import java.util.ArrayList;
import java.util.List;

public class Page<T> {
	
	private int totalRecord;		//总记录数
	private int pageNum;			//当前页
	private int pageSize = 10; 			//每页显示记录数
	private int totalPage;			//总页码
	private int startPage;			//起始页
	private int endPage;          //结束页
	
	private List<T> list = new ArrayList<T>();

	public Page(int totalRecord, int pageNum) {
		this(totalRecord, pageNum, 10);
	}

	public Page(int totalRecord, int pageNum, int pageSize) {
		this.totalRecord = totalRecord;
		this.pageNum = pageNum;
		if(pageSize != 0) this.pageSize = pageSize;
		
		this.totalPage = (this.totalRecord + (this.pageSize - 1))/this.pageSize;
		
		if(totalPage < 10) {
			startPage = 1;
			endPage = totalPage;
		} else {
			startPage = pageNum - 5;
			endPage = pageNum + 4;
			if(startPage < 1) {
				startPage = 1;
			}
			if(endPage > totalPage) {
				endPage = totalPage;
			}
		}
	}

	public int getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getStartPage() {
		return startPage;
	}

	public void setStartPage(int startPage) {
		this.startPage = startPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}
}
